/*
 * @author       :成家杰
 * @date         :2022-06-21 17:13:37
 * @Description  : com.tj.controller
 * @version      : 1.0
 */


package com.tj.controller;

import com.tj.pojo.Hospital;
import com.tj.service.HospitalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/hospital")
public class HospitalController {
    @Autowired
    private HospitalService hospitalService;
    
    //增加数据
    @RequestMapping("/insertHospital")
    public Map<String, Object> insertHospital(@RequestParam String name,@RequestParam String picture,@RequestParam String telephone,@RequestParam String address,@RequestParam String businessHours,@RequestParam String deadline,@RequestParam String rule,@RequestParam int state) throws Exception {
       int hospitalList = hospitalService.insert(name, picture, telephone, address, businessHours, deadline, rule, state);
        Map<String, Object> map = new HashMap<>();
        map.put("status", "1");
        map.put("hospitalList", hospitalList);
        return map;
        
    }
    //查询所有数据
    @RequestMapping("/getHospitalList")
    public Map<String, Object> getHospitalList() throws Exception {
        List<Hospital> hospitalList = hospitalService.selectAll();
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("status", "1");
        map.put("hospitalList",hospitalList);
        return map;
    }
    
    //单个查询id查询
    @RequestMapping("/getHospitalOne")
    public Map<String, Object> getHospitalDetail(@RequestParam Integer id) throws Exception {
        List<Hospital> hospitalOne = hospitalService.selectByHospitalId(id);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("status", "1");
        map.put("hospitalList", hospitalOne);
        return map;
    }
    
    
    //删除数据
    @RequestMapping("/deletHospital")
    public Map<String, Object> delete(@RequestParam Integer id) throws Exception {
        int hospitalList = hospitalService.delete(id);
        Map<String, Object> map = new HashMap<>();
        map.put("status", "0");
        map.put("hospitalList",hospitalList);
        return map;
    }
    
    //更新数据
    @RequestMapping("/updateHospital")
    public Map<String, Object> updateHospital(@RequestParam Integer id, @RequestParam String name,@RequestParam String picture,@RequestParam String telephone,@RequestParam String address,@RequestParam String businessHours,@RequestParam String deadline,@RequestParam String rule,@RequestParam int state) throws Exception {
        int hospitalList = hospitalService.update(id,name, picture, telephone, address, businessHours, deadline, rule, state);
        Map<String, Object> map = new HashMap<>();
        map.put("status", "1");
        map.put("hospitalList",hospitalList);
        return map;
    }
    
    //按name模糊查询
    @RequestMapping("/Fuzzyquery")
    public Map<String, Object> Fuzzyquery(@RequestParam String name) throws Exception {
        List<Hospital> hospitalList = hospitalService.Fuzzyquery(name);
        Map<String, Object> map = new HashMap<>();
        map.put("status", "1");
        map.put("hospitalList",hospitalList);
        return map;
    }
}
